package com.wbao.dianniu.ui;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;

import com.umeng.analytics.MobclickAgent;
import com.wbao.dianniu.R;
import com.wbao.dianniu.utils.AppUtil;

import qiu.niorgai.StatusBarCompat;


/**
 * Created by suanzi on 2016/3/23.
 */
public abstract class SingleFragmentActivity extends FragmentActivity {

    protected abstract Fragment createFragment();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_single_fragment);
        FragmentManager fm = getSupportFragmentManager();
        Fragment fragment = fm.findFragmentById(R.id.fragmentContainer); // 主要所有Fragment的id都必须是这个
        if (fragment == null) {
            fragment = createFragment();
            fm.beginTransaction().add(R.id.fragmentContainer, fragment).commit();
        }
        // 场景类型设置接口 ---普通统计场景类型
        MobclickAgent.openActivityDurationTrack(false);
        MobclickAgent.setScenarioType(this, MobclickAgent.EScenarioType.E_UM_NORMAL);
        StatusBarCompat.setStatusBarColor(this, Color.parseColor("#39bf9e"), 0);
        AppUtil.setActivity(this);// 保存当前的activity
        AppUtil.setContext(getApplicationContext()); // 保存context
    }

    protected void onResume() {
        super.onResume();
        AppUtil.setActivity(this);
        AppUtil.setContext(getApplicationContext()); // 保存context
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

}
